package com.acme.domain.bank;

import java.io.Serializable;
import java.util.ArrayList;

import com.acme.exceptions.ClientExistsException;

public class Bank implements Serializable {

	private static final long serialVersionUID = 1L;
	private final ArrayList<Client> clients = new ArrayList<Client>();
	
	public void addClient(final Client client) throws ClientExistsException{
		if(!exists(client)) {	
			this.clients.add(client);
		}
		else {
			throw new ClientExistsException("This client already exists in bank!");
		}
	}
	
	public ArrayList<Client> getClients() {
		return this.clients;
	}
	
	private boolean exists(Client client) {
		for(Client cl: this.clients) {
			if(client.getName() == cl.getName()) {
				return true;
			}
		}
		return false;
	}
}